﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace NJL.WebUsers
{
    public partial class Play : BasePageVisitor
    {
        private readonly NJL.BLL.NJL_COMPANY bllCompany = new BLL.NJL_COMPANY();
        private readonly NJL.BLL.NJL_COMPANY_SERVICE bllService = new BLL.NJL_COMPANY_SERVICE();
        private readonly NJL.BLL.NJL_NEWS bllNews = new BLL.NJL_NEWS();
        private readonly NJL.BLL.NJL_ATTRACTION bllAtt = new BLL.NJL_ATTRACTION();
        private readonly NJL.BLL.NJL_PERSON bllPerson = new BLL.NJL_PERSON();
        private readonly NJL.BLL.NJL_LOCAL_COLOR bllLocalColor = new BLL.NJL_LOCAL_COLOR();
        private readonly NJL.BLL.NJL_USER bllUser = new BLL.NJL_USER();
        private readonly NJL.BLL.NJL_CS_AREA bllArea = new BLL.NJL_CS_AREA();
        private readonly NJL.BLL.NJL_SYS_NEWS bllsysNews = new BLL.NJL_SYS_NEWS();

        DataSet ds;

        protected int PROVINCE_COUNT = 0;
        protected int CITY_COUNT = 0;
        protected int COMPANY_COUNT = 0;
        protected int USER_COUNT = 0;
        protected int LOCAL_COLOR_COUNT = 0;
        protected int ATTRACTION_COUNT = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
                base.LoadPageSeoInformation("看别人玩什么");
            }
        }
        private void bind()
        {
            #region 农家乐
            if (WEBSITE_FOCUS_CITY_CODE != "")
            {
                ds = bllCompany.GetAllList(9, "NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and TYPE_CODE='1' and AREA_CODE='" + WEBSITE_FOCUS_CITY_CODE + "'", "VISIT_COUNT desc");
            }
            else
            {
                ds = bllCompany.GetAllList(9, "NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and TYPE_CODE='1'", "VISIT_COUNT desc");
            }
            rptContent.DataSource = ds;
            rptContent.DataBind();
            #endregion 
            #region 度假山庄
            if (WEBSITE_FOCUS_CITY_CODE != "")
            {
                ds = bllCompany.GetAllList(9, "NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and TYPE_CODE='2' and AREA_CODE='" + WEBSITE_FOCUS_CITY_CODE + "'", "VISIT_COUNT desc");
            }
            else
            {
                ds = bllCompany.GetAllList(9, "NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and TYPE_CODE='2'", "VISIT_COUNT desc");
            }
            rptContentdjsz.DataSource = ds;
            rptContentdjsz.DataBind();
            #endregion
            #region 服务列表
            if (WEBSITE_FOCUS_CITY_CODE != "")
            {
                ds = bllService.GetList(8, "NJL_COMPANY_ID in (select ID from NJL_COMPANY where AREA_CODE='" + WEBSITE_FOCUS_CITY_CODE + "' and NJL_SYS_BASE_ID='" + WEBSITE_CODE + "')", "VISIT_COUNT desc,CREATE_DATE_TIME desc");
            }
            else
            {
                ds = bllService.GetList(8, "NJL_COMPANY_ID in (select ID from NJL_COMPANY where NJL_SYS_BASE_ID='" + WEBSITE_CODE + "')", "VISIT_COUNT desc,CREATE_DATE_TIME desc");
            }
            rptServiceList.DataSource = ds;
            rptServiceList.DataBind();
            #endregion
            #region 游记
            ds = bllNews.GetList(3, "NJL_SYS_BASE_ID='" + WEBSITE_CODE + "'", "VISIT_COUNT desc,CREATE_DATE_TIME desc");
            rptyj.DataSource = ds;
            rptyj.DataBind();
            #endregion
            #region 分享
            ds = bllNews.GetList(8, "NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and TYPE_CODE='101'", "VISIT_COUNT desc,CREATE_DATE_TIME desc");
            rptShare.DataSource = ds;
            rptShare.DataBind();
            #endregion 
            #region 周边景点
            if (WEBSITE_FOCUS_CITY_CODE != "")
            {
                ds = bllAtt.GetList(10, "NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and AREA_CODE='" + WEBSITE_FOCUS_CITY_CODE + "' and IMAGE_CODE not is null", "CREATE_DATE_TIME desc");
            }
            else
            {
                ds = bllAtt.GetList(10, "NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and IMAGE_CODE is not null", "CREATE_DATE_TIME desc");
            }
            rptAttr.DataSource = ds;
            rptAttr.DataBind();
            #endregion
            #region 用户
            ds = bllPerson.GetListUserMaxNews(12, "b.NJL_SYS_BASE_ID='" + WEBSITE_CODE + "'", "newscount desc,a.CREATE_DATE_TIME desc");
            rptUser.DataSource = ds;
            rptUser.DataBind();
            #endregion
            #region 最新认证
            if (WEBSITE_FOCUS_CITY_CODE != "")
            {
                ds = bllCompany.GetAllList(3, "NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and TYPE_CODE='1' and AREA_CODE='" + WEBSITE_FOCUS_CITY_CODE + "'", "VISIT_COUNT desc,CREATE_DATE_TIME desc");
            }
            else
            {
                ds = bllCompany.GetAllList(3, "NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and TYPE_CODE='1'", "VISIT_COUNT desc,CREATE_DATE_TIME desc");
            }
            rptShoprz.DataSource = ds;
            rptShoprz.DataBind();
            #endregion
            #region 最新授权
            if (WEBSITE_FOCUS_CITY_CODE != "")
            {
                ds = bllCompany.GetAllList(3, "NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and TYPE_CODE='1' and AREA_CODE='" + WEBSITE_FOCUS_CITY_CODE + "' and ID not in(select top 3 ID from NJL_COMPANY where NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and TYPE_CODE='1' and AREA_CODE='" + WEBSITE_FOCUS_CITY_CODE + "' order by VISIT_COUNT desc,CREATE_DATE_TIME desc)", "VISIT_COUNT desc,CREATE_DATE_TIME desc");
            }
            else
            {
                ds = bllCompany.GetAllList(3, "NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and TYPE_CODE='1' and ID not in(select top 3 ID from NJL_COMPANY where NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and TYPE_CODE='1' order by VISIT_COUNT desc,CREATE_DATE_TIME desc)", "VISIT_COUNT desc,CREATE_DATE_TIME desc");
            }
            rptShopsq.DataSource = ds;
            rptShopsq.DataBind();
            #endregion
            #region 行家周点评
            ds = bllsysNews.GetList(1, "TYPE_CODE='51' and NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and IS_INDEX=1 and IS_PUBLISH=1", "SORT desc,CREATE_DATE_TIME desc");
            rptfirstdianping.DataSource = ds;
            rptfirstdianping.DataBind();
            ds = bllsysNews.GetList(4, "TYPE_CODE='51' and NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and IS_INDEX=1 and IS_PUBLISH=1 and ID not in(select top 1 ID from NJL_SYS_NEWS where TYPE_CODE='51' and NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and IS_INDEX=1 and IS_PUBLISH=1 order by SORT desc,CREATE_DATE_TIME desc)", "SORT desc,CREATE_DATE_TIME desc");
            rptdianping.DataSource = ds;
            rptdianping.DataBind();
            #endregion

            //PROVINCE_COUNT = bllArea.GetModelList(" deep=1 ").Count;
            CITY_COUNT = bllArea.GetModelList(" deep=2 and AREA_CODE like '" + WEBSITE_CODE.Substring(0, 2) + "%' ").Count;
            COMPANY_COUNT = bllCompany.GetListCount(" NJL_COMPANY.NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' ");
            //USER_COUNT = bllUser.GetModelList(" NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' ").Count;
            USER_COUNT = bllUser.GetModelList(" ").Count;
            LOCAL_COLOR_COUNT = bllLocalColor.GetModelList(" NJL_LOCAL_COLOR.NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' ").Count;
            ATTRACTION_COUNT = bllAtt.GetModelList(" NJL_ATTRACTION.NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' ").Count;

        }
        protected void rptContent_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Literal litNum = e.Item.FindControl("litNum") as Literal;
                if (e.Item.ItemIndex < 3)
                {
                    litNum.Text = "<div class=\"item_no no_" + (e.Item.ItemIndex + 1).ToString() + "\"></div>";
                }
                DataRowView drv = (DataRowView)e.Item.DataItem;
                string id = drv["ID"].ToString();
                Repeater rpt = e.Item.FindControl("rptService") as Repeater;
                ds = bllService.GetList(3, "NJL_COMPANY_ID='" + id + "'", "VISIT_COUNT desc");
                rpt.DataSource = ds;
                rpt.DataBind();
            }
        }
        protected void rptContentdjsz_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Literal litNum = e.Item.FindControl("litNumdjsz") as Literal;
                if (e.Item.ItemIndex < 3)
                {
                    litNum.Text = "<div class=\"item_no no_" + (e.Item.ItemIndex + 1).ToString() + "\"></div>";
                }
                DataRowView drv = (DataRowView)e.Item.DataItem;
                string id = drv["ID"].ToString();
                Repeater rpt = e.Item.FindControl("rptServicedjsz") as Repeater;
                ds = bllService.GetList(3, "NJL_COMPANY_ID='" + id + "'", "VISIT_COUNT desc");
                rpt.DataSource = ds;
                rpt.DataBind();

            }
        }

        protected void rptUser_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView drv = (DataRowView)e.Item.DataItem;
                string id = drv["ID"].ToString();
                Repeater rpt = e.Item.FindControl("rptUserNews") as Repeater;
                ds = bllNews.GetList(4, "NJL_PERSON_ID='" + id + "'", "VISIT_COUNT desc");
                rpt.DataSource = ds;
                rpt.DataBind();
            }
        }

    }
}